package com.biz.primus.app.rest.controller.order;

import com.biz.primus.app.rest.controller.base.RestBaseController;
import com.biz.primus.app.rest.feign.order.ReturnOrderFeignClient;
import com.biz.primus.base.support.rest.vo.JsonResult;
import com.biz.primus.base.global.GlobalParams;
import com.biz.primus.model.order.vo.aftersale.ReturnCodeVO;
import com.biz.primus.model.order.vo.aftersale.ReturnOrderAddLogisticsRequestVO;
import com.biz.primus.model.order.vo.aftersale.ReturnOrderRequestVO;
import com.biz.primus.model.order.vo.request.OrderCodeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 退货单控制器
 *
 * @author Tiger Feng
 * @date 2017年11月24日
 */
@RestController
@RequestMapping("order/returnOrder")
@Api("退货单相关接口文档")
public class ReturnOrderController extends RestBaseController {
    @Autowired
    private ReturnOrderFeignClient returnOrderFeignClient;

    @ApiOperation(value = "查询订单信息以用于售后服务", notes = "根据订单编码获取订单信息，以便用于售后界面展示")
    @GetMapping("queryByOrderCode4AfterSale")
    public JsonResult queryByOrderCode4AfterSale(
            GlobalParams gp,
            @RequestBody OrderCodeVO orderCodeVO) {
        super.buildRequest(gp, orderCodeVO);
        return new JsonResult(returnOrderFeignClient.queryByOrderCode4AfterSale(orderCodeVO));
    }

    @ApiOperation(value = "申请退货单", notes = "申请创建退货单")
    @PostMapping("applyReturnOrder")
    public JsonResult applyReturnOrder(
            GlobalParams gp,
            @RequestBody ReturnOrderRequestVO returnOrderRequestVO) {
        super.buildRequest(gp, returnOrderRequestVO);
        return new JsonResult(returnOrderFeignClient.applyReturnOrder(returnOrderRequestVO));
    }

    @ApiOperation(value = "查询退货单", notes = "根据订单编码获取退货单，当前订单的退货单，一个订单只能有一个退货单")
    @GetMapping("queryByOrderCode")
    public JsonResult queryByOrderCode(
            GlobalParams gp,
            @RequestBody OrderCodeVO orderCodeVO) {
        super.buildRequest(gp, orderCodeVO);
        return new JsonResult(returnOrderFeignClient.queryByOrderCode(orderCodeVO));
    }

    @ApiOperation(value = "补充退货单物流信息", notes = "用户将退货商品回寄的物流单号、物流名称等信息补充到退货单中")
    @PostMapping("addLogisticsInfo")
    public JsonResult addLogisticsInfo(
            GlobalParams gp,
            @RequestBody ReturnOrderAddLogisticsRequestVO returnOrderAddLogisticsRequestVO) {
        super.buildRequest(gp, returnOrderAddLogisticsRequestVO);
        return new JsonResult(returnOrderFeignClient.addLogisticsInfo(returnOrderAddLogisticsRequestVO));
    }

    @ApiOperation(value = "取消退货单", notes = "用户取消退货单，需要传入退货单,成功返回true")
    @PostMapping("cancelReturnOrder")
    public JsonResult cancelReturnOrder(
            GlobalParams gp,
            @RequestBody ReturnCodeVO returnCodeVO) {
        super.buildRequest(gp, returnCodeVO);
        return new JsonResult(returnOrderFeignClient.cancelReturnOrder(returnCodeVO));
    }

}
